/**
 * 新增非平台设施消耗收货详情
 * 胡琼
 * 2017/8/21
 **/
var testConfig = require('../testConfig');
const ipcRenderer = require('electron').ipcRenderer;
var l = parseInt(window.sessionStorage.getItem("runTimes"));
var planData = JSON.parse(window.sessionStorage.getItem('planData'));
var caseData =  planData.cases[l];
var msg = {
    reportId:planData.reportId,
    taskId:planData.taskId,
    caseId:caseData.caseId,
    caseNumber:caseData.caseNumber,
    isOver:'false'
};
function TestProject() {
    this.init = function () {
        var arr = [];
        arr.push(this.step1,
            this.step2,
            this.step3,
            this.step4,
            this.step5,
            this.step6,
            this.step7,
            this.step8,
            this.step9,
            this.step10,
            this.step11,
            this.step12,
            this.step13);
        testConfig.testFun.runStep(arr);
    };
    this.step1 = function () {
        $("#aside-nav").find("div.coords").eq(2).find("a")[0].click();
        msg.stepResult = {
            byname:"skipProInfo",
            realData:$("#contentIframe iframe").attr('src')
        };
        ipcRenderer.sendToHost(JSON.stringify(msg));
    };
    this.step2 = function () {
        $("#collapse3").find("li:nth-child(2) .second_lv_li")[0].click();
        msg.stepResult = {
            byname:"skipSiteDataManage",
            realData:$("#contentIframe iframe").attr('src')
        };
        ipcRenderer.sendToHost(JSON.stringify(msg));
    };
    this.step3 = function () {
        testConfig.testFun.ai().find("input[data-name='projectCode']").val('PC99254EUK98');
        testConfig.testFun.ai().find("#search")[0].click();
        testConfig.testFun.ai().find("tr[data-index='0'] td")[0].click();
        msg.stepResult = {
            byname:"skipWorkerAttend",
            realData:testConfig.testFun.bi().find("#layui-layer-iframe1").attr('src')
        };
        ipcRenderer.sendToHost(JSON.stringify(msg));
    };
    this.step4 = function () {
        testConfig.testFun.bi().find(".manage li:nth-child(4)")[0].click();
        msg.stepResult = {
            byname:"skipPlatformInstall",
            realData:testConfig.testFun.bi().find("#layui-layer-iframe1").attr('src')
        };
        ipcRenderer.sendToHost(JSON.stringify(msg));
    };
    this.step5 = function () {
        testConfig.testFun.bi().find(".facility-three li:nth-child(2)")[0].click();
        msg.stepResult = {
            byname:"skipNoPlatformInstall",
            realData:testConfig.testFun.bi().find("#layui-layer-iframe1").attr('src')
        };
        ipcRenderer.sendToHost(JSON.stringify(msg));
    };
    this.step6 = function () {
        testConfig.testFun.bi().find("#add_f")[0].click();
        msg.stepResult = {
            byname:"addDeliverDetailPop",
            realData:testConfig.testFun.bi().find("#layer_addform3")
        };
        ipcRenderer.sendToHost(JSON.stringify(msg));
    };
    this.step7 = function () {
        testConfig.testFun.bi().find("#id-category-3")[0].click();
        testConfig.testFun.bi().find(".dep-1 li:nth-child(1)").click();
        testConfig.testFun.bi().find(".dep-2 li:nth-child(1)").click();
        testConfig.testFun.bi().find(".dep-3 li:nth-child(8)").click();
        msg.stepResult = {
            byname:"breed",
            realData:testConfig.testFun.bi().find("#id-category-3 input[data-name='1762']").val()
        };
        ipcRenderer.sendToHost(JSON.stringify(msg));
    };
    this.step8 = function () {
        testConfig.testFun.bi().find("input[data-name='attribute']").val('平方米');
        msg.stepResult = {
            byname:"attribute",
            realData:testConfig.testFun.bi().find("input[data-name='attribute']").val()
        };
        ipcRenderer.sendToHost(JSON.stringify(msg));
    };
    this.step9 = function () {
        testConfig.testFun.bi().find("input[data-name='receptionAt']").val('2017-08-08');
        msg.stepResult = {
            byname:"receptionAt",
            realData:testConfig.testFun.bi().find("input[data-name='receptionAt']").val()
        };
        ipcRenderer.sendToHost(JSON.stringify(msg));
    };
    this.step10 = function () {
        testConfig.testFun.bi().find("input[data-name='quantity']").val('100');
        msg.stepResult = {
            byname:"quantity",
            realData:testConfig.testFun.bi().find("input[data-name='quantity']").val()
        };
        ipcRenderer.sendToHost(JSON.stringify(msg));
    };
    this.step11 = function () {
        testConfig.testFun.bi().find("#form3 .saveBtn")[0].click();
        msg.stepResult = {
            byname:"hold",
            realData:testConfig.testFun.bi().find("#layui-layer-iframe1").attr('src')
        };
        ipcRenderer.sendToHost(JSON.stringify(msg));
    };
    this.step12 = function () {
        testConfig.testFun.bi().find("#id-facility-category")[0].click();
        testConfig.testFun.bi().find(".dep-1 li:nth-child(1)").click();
        testConfig.testFun.bi().find(".dep-2 li:nth-child(1)").click();
        testConfig.testFun.bi().find(".dep-3 li:nth-child(8)").click();
        msg.stepResult = {
            byname:"selectBreed",
            realData:testConfig.testFun.bi().find("#id-facility-category input[data-name='1762']").val()
        };
        ipcRenderer.sendToHost(JSON.stringify(msg));
    };
    this.step13 = function(){
        var address = window.location.href;
        var r = parseInt(window.sessionStorage.getItem("runTimes"));
        if(planData.cases[r+1].caseNumber){
            if (address.indexOf("?") > 0) {
                window.location.href = address + "&_from=" + planData.cases[r+1].caseNumber;
            } else {
                window.location.href = address + "?_from=" + planData.cases[r+1].caseNumber;
            }
        }
        window.sessionStorage.setItem("runTimes",r+1);
    }
}
function testStart() {
    var test = new TestProject();
    test.init();
}
exports.start = testStart;
